/** @file    wCore_Object.cpp
 *  @author  Alessandro Polo
 *  @version $Id: wCore_Object.cpp 2618 2010-06-04 09:48:15Z alex $
 *  @brief
 * File containing methods for the wosh::gui::wCore_Object class.
 * The header for this class can be found in wCore_Object.h, check that file
 * for class description.
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

 #include "wCore_Object.h"

 #include <core/ObjectAllocator.h>
 #include <framework/gui/GuiUtilities.h>


using namespace std;
namespace wosh {
 namespace gui {

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

QVariant ObjectTypeInfoListModel::data( const QModelIndex &index, int role ) const {
	if ( !index.isValid() )	return QVariant();
	const ObjectTypeInfo& objinfo = this->class_list.at(index.row());
	if ( role == Qt::DisplayRole || role == Qt::EditRole ) { // cos completer!
		switch (index.column()) {
			case 0: return QVariant(objinfo.name.c_str());
			case 1: return QVariant(objinfo.version);
			case 2: return QVariant(objinfo.allocable);
			case 3: return QVariant(objinfo.parent.c_str());
			default:
				return QVariant();
		 }
	 }
	else if ( role == Qt::ToolTipRole ) {
		return QVariant( objinfo.name.c_str() );
	 }
	else if ( index.column() == 0 && role == Qt::DecorationRole ) {
		return QVariant( GuiUtilities::createIconFor(objinfo.name) );
	 }
	return QVariant();
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

QVariant ObjectTypeInfoTableModel::data(const QModelIndex &index, int role) const {
	if (  !index.isValid() ) return QVariant();
	const ObjectTypeInfo& objinfo = this->class_list.at(index.row());
	if ( role == Qt::DisplayRole || role == Qt::EditRole ) { // cos completer!
		switch (index.column()) {
			case 0: return QVariant(objinfo.name.c_str());
			case 1: return QVariant(objinfo.version);
			case 2: return QVariant(objinfo.allocable);
			case 3: return QVariant(objinfo.parent.c_str());
			default:
				return QVariant();
		 }
	 }
	else if ( role == Qt::ToolTipRole ) {
		return QVariant( objinfo.name.c_str() );
	 }
	else if ( index.column() == 0 && role == Qt::DecorationRole ) {
		return QVariant( GuiUtilities::createIconFor(objinfo.name) );
	 }
	return QVariant();
 }

QVariant ObjectTypeInfoTableModel::headerData(int section, Qt::Orientation orientation, int role) const {
	if (role != Qt::DisplayRole) return QVariant();
	 if (orientation == Qt::Horizontal ) {
		switch(section) {
			case 0: return QVariant("Name");
			case 1: return QVariant("Version");
			case 2: return QVariant("Allocable");
			case 3: return QVariant("Parent");
			default: return QVariant("");
		 }
	 }
	return QVariant();
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////






 }; // namespace gui
}; // namespace wosh
